package com.loren.oauth.data.resp;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

@Getter
@Setter
@ToString
@AllArgsConstructor
public class MicroResponse<T> extends ResponseCode implements Serializable {

	private static final long serialVersionUID = 6706993368630319830L;

	private boolean success;

	private int code;

	private String message;

	private T body;

	public static MicroResponse<?> success() {
		return new MicroResponse<>(true, SUCCESS_CODE, "success", null);
	}

	public static <T> MicroResponse<T> success(T body) {
		return new MicroResponse<>(true, SUCCESS_CODE, "success", body);
	}

	public static MicroResponse<?> failure(String message) {
		return new MicroResponse<>(false, FAILURE_CODE, message, null);
	}

	public static MicroResponse<?> failure(int code, String message) {
		return new MicroResponse<>(false, code, message, null);
	}
}
